﻿using Umbraco.Cms.Web.Model.BackOffice.PropertyEditors;
using System.Web.UI;
using Umbraco.Cms.Web.Context;
using Umbraco.Framework;

[assembly: WebResource("idseefeld.com.imagecropper.Resources.jquery.Jcrop.min.js", "application/x-javascript")]
[assembly: WebResource("idseefeld.com.imagecropper.Resources.cropper.js", "application/x-javascript")]
[assembly: WebResource("idseefeld.com.imagecropper.Resources.cropper.css", "text/css", PerformSubstitution = true)]
[assembly: WebResource("idseefeld.com.imagecropper.Resources.jquery.Jcrop.min.css", "text/css", PerformSubstitution = true)]
[assembly: WebResource("idseefeld.com.imagecropper.Resources.Jcrop.gif", "image/gif")]


namespace idseefeld.com.imagecropper
{
	/// <summary>
	/// Image Cropper for Umbraco 5 - released under MIT License
	/// Copyright (c) 2012 Dirk Seefeld
	/// http://imagecropperumbraco5.codeplex.com/
	/// </summary>
	[PropertyEditor("B9C8C068-9193-4422-A717-ED28C0E48BBD", "idseefeld.com.imagecropper", "Image Cropper")]
	public class ImageCropperV5 : ContentAwarePropertyEditor<ImageCropperV5Model, ImageCropperV5PreValueModel>
	{
		private readonly IBackOfficeRequestContext _backOfficeRequestContext;

		public ImageCropperV5(IBackOfficeRequestContext backOfficeRequestContext)
		{
			_backOfficeRequestContext = backOfficeRequestContext;
		}

		public override ImageCropperV5Model CreateEditorModel(ImageCropperV5PreValueModel preValues)
		{
			return new ImageCropperV5Model(preValues, _backOfficeRequestContext,
				GetContentModelValue(x => x.Id, HiveId.Empty),
				GetContentPropertyValue(x => x.Alias, ""));
		}

		public override ImageCropperV5PreValueModel CreatePreValueEditorModel()
		{
			ImageCropperV5PreValueModel rVal = new ImageCropperV5PreValueModel();
			if (rVal.quality == 0)
				rVal.quality = 75;
			return rVal;
		}
	}
}
